<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%--项目绝对路径--%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%--获取当前时间--%>
<jsp:useBean id="now" class="java.util.Date" scope="page"/>
<fmt:formatDate var="nowTime" value="${now}" pattern="yyyy-MM-dd HH:mm:ss"/>
<html>
<%

   Integer id = Integer.valueOf(request.getParameter("id"));


    String sql = "SELECT  * from user where id = "+id;

    String username =null;

    String name = null;
    String phone = null;
    String depart = null;
    String createtime = null;
    String avatar =null;
    String  password = null;

    //jdbc:mysql


    System.out.println("执行了sql =====》"+sql);
    String url = "jdbc:mysql://localhost:3306/carxianyu";
    String user = "root";
    String pwd = "root";
    Class.forName("com.mysql.jdbc.Driver");//加载驱动
    Connection conn = DriverManager.getConnection("jdbc:mysql://43.142.239.28:13307/carxianyu?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC","root","root");
    PreparedStatement a = conn.prepareStatement(sql);
    ResultSet rs = a.executeQuery();

    while (rs.next() ){

        username   =  rs.getString("username");
        name = rs.getString("name");
        phone = rs.getString("phone");
        avatar = rs.getString("avatar");
        createtime =  rs.getString("createtime");
        password = rs.getString("password");
      depart = String.valueOf(rs.getInt("depart"));
    }
%>

<head>
    <title>用户修改页面</title>
    <!-- 引入css样式和js文件-->
    <meta charset="UTF-8">
    <base href="${ctx}/"/>
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${ctx}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${ctx}/static/js/common.js"></script>
    <script>
        var ctx = '${ctx}/';
    </script>
</head>
<body>
<div class="layui-container">


    <form class="layui-form  layui-form-pane" action="${ctx}/view/back/user/doUserExcute.jsp" method="post" style="margin: 50px auto;">

        <div class="layui-form-item" hidden>
            <label class="layui-form-label">用户编号</label>
            <div class="layui-input-block">
                <input type="text" name="id" id="id" value="<%=id%>" lay-verify autocomplete="off"
                       placeholder=""
                       class="layui-input"     hidden  >
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" id="adminname" value="<%=username%>" lay-verify autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </div>
        </div>
<c:if test="${sessionScope.depart == 22}">
        <div class="layui-form-item">
            <label class="layui-form-label">用户密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" id="adminpwd" value="<%=password%>" lay-verify autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </div>
        </div>
</c:if>

        <c:if test="${sessionScope.depart == 11}">
        <div class="layui-form-item">
            <label class="layui-form-label">用户角色</label>
            <div class="layui-input-block">
                <select name="depart" id="depart" class="layui-select">
                    <option value="22">会员</option>
                    <option value="11">系统管理员</option>
                </select>
            </div>
        </div>
        </c:if>


        <div class="layui-form-item">
            <label class="layui-form-label">用户头像url</label>
            <div class="layui-input-block">
                <input type="text" name="avatar" id="avatar" value="<%=avatar%>" lay-verify autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户真名</label>
            <div class="layui-input-block">
                <input type="text" name="name" id="name" value="<%=name%>" lay-verify autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电话号码</label>
            <div class="layui-input-block">
                <input type="text" name="phone" id="" value="<%=phone%>" lay-verify autocomplete="off"
                       placeholder=""
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" hidden>
            <label class="layui-form-label">是否修改</label>
            <div class="layui-input-block">
                <select name="state" id="state" class="layui-select">
                    <option value="2" selected>是</option>
                </select>
            </div>
        </div>








        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    //定义layui的变量
    var $;
    var layer;
    var element;
    var form;
    layui.use(['element', 'layer', 'jquery', 'form', 'laydate', 'layedit'], function () {
        element = layui.element;
        layer = layui.layer;
        $ = layui.jquery;
        form = layui.form;
        var laydate = layui.laydate;
        var layedit = layui.layedit;

        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log(JSON.stringify(data.field));
            return true;
        });

    });
</script>

</body>
</html>
